Routines (alphabetical) > Routines: L > LA_LEAST_SQUARES

LA_LEAST_SQUARES

Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also

The LA_LEAST_SQUARES function is used to solve the linear least-squares problem:

Minimizex ||Ax - b||2

where A is a (possibly rank-deficient) n-column by m-row array, b is an m-element input vector, and x is the n-element solution vector. There are three possible cases:

The LA_LEAST_SQUARES function may also be used to solve for multiple systems of least squares, with each column of b representing a different set of equations. In this case, the result is a k-by-n array where each of the k columns represents the solution vector for that set of equations.

LA_ LEAST_SQUARES is based on the following LAPACK routines:

LAPACK Routine Basis for LA_LEAST_SQUARES

Output Type

LAPACK Routines

Float

sgels, sgelsy, sgelss, sgelsd

Double

dgels, dgelsy, dgelss, dgelsd

Complex

cgels, cgelsy, cgelss, cgelsd

Double complex

zgels, zgelsy, zgelss, zgelsd

For details see Anderson et al., LAPACK Users' Guide, 3rd ed., SIAM, 1999.

Syntax

Result = LA_LEAST_SQUARES( A, B [, /DOUBLE] [, METHOD=value] [, RANK=variable] [, RCONDITION=value] [, RESIDUAL=variable] [, STATUS=variable] )

Return Value

The result is an n-element vector or k-by-n array.

Arguments

A

The n-by-m array used in the least-squares system.

B

An m-element input vector containing the right-hand side of the linear least-squares system, or a k-by-m array, where each of the k columns represents a different least-squares system.

Keywords

DOUBLE

Set this keyword to use double-precision for computations and to return a double-precision (real or complex) result. Set DOUBLE = 0 to use single-precision for computations and to return a single-precision (real or complex) result. The default is /DOUBLE if A is double precision, otherwise the default is DOUBLE = 0.

METHOD

Set this keyword to indicate which computation method to use. Possible values are:

RANK

Set this keyword to a named variable in which to return the effective rank of A. If METHOD = 0 or the array is full rank, then RANK will have the value MIN(m, n).

RCONDITION

Set this keyword to the reciprocal condition number used as a cutoff value in determining the effective rank of A. Arrays with condition numbers larger than 1/RCONDITION are assumed to be rank deficient. If RCONDITION is set to zero or omitted, then array A is assumed to be of full rank. This keyword is ignored for METHOD = 0.

RESIDUAL

If m > n and the rank of A is n (the system is overdetermined), then set this keyword to a named variable in which to return the residual sum-of-squares for Result. If B is an m-element vector then RESIDUAL will be a scalar; if B is a k-by-m array then RESIDUAL will be a k-element vector containing the residual sum-of-squares for each system of equations. If m n or A is rank deficient (rank < n) then the values in RESIDUAL will be zero.

STATUS

Set this keyword to a named variable that will contain the status of the computation. Possible values are:

Examples

Given the following under determined system of equations:

2t + 5u + 3v + 4w = 3

7t + u + 3v + 5w = 1

4t + 3u + 6v + 2w = 6

The following program can be used to find the solution:

; Define the coefficient array:
a = [[2, 5, 3, 4], $
     [7, 1, 3, 5], $
     [4, 3, 6, 2]]

; Define the right-hand side vector b:
b = [3, 1, 6]

; Find and print the minimum norm solution of a:
x = LA_LEAST_SQUARES(a, b)
PRINT, 'LA_LEAST_SQUARES solution:', x

IDL prints:

LA_LEAST_SQUARES solution:

-0.0376844 0.350628 0.986164 -0.409066

Version History

5.6

Introduced

See Also

LA_GM_LINEAR_MODEL , LA_LEAST_SQUARE_EQUALITY